namespace UserService;

using Microsoft.AspNetCore.Mvc;
using System.ComponentModel.DataAnnotations;

[ApiController]
[Route("[controller]")]
public class ServiceController : Controller
{
    public IUserService service { get; set; }
    public ServiceController(IUserService userService)
    {
        service = userService;
    }
    // 普通方法依赖抽象
    [HttpGet]
    [Route("/get")]
    public string Get([Required] int index)
    {
        IUserService userService = new UserService();
        return userService.FetchName(index);
    }
    // 依赖注入依赖抽象(见program.cs Ln14)

    [HttpGet]
    public string? GetName(int index)
    {
        // service.AddName();
        return service.FetchName(index);
    }
    [HttpPost]
    public bool SetName(string name)
    {
        return service.AddName(name);
    }
}
